package com.example.myapplication;

import android.annotation.SuppressLint;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.example.myapplication.databinding.ActivityAlertDialogBinding;

public class AlertDialogActivity extends AppCompatActivity {
    private String[] textSizeArr = {"小", "中", "大"};
    private int[] textnumberArr = {10, 30, 50};
    private  int index = 0;
//    private TextView textSizeview;
//    private TextView texthobbyview;
    private String[] hobbyArr = {"唱歌", "跳舞", "rap"};
    private  String hobby = "";

    private ActivityAlertDialogBinding binding;
    @SuppressLint("MissingInflatedId")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        binding = ActivityAlertDialogBinding.inflate(getLayoutInflater());
//        setContentView(R.layout.activity_alert_dialog);
//        textSizeview = findViewById(R.id.textsizeview);
//        texthobbyview = findViewById(R.id.texthobbyview);
        setContentView(binding.getRoot());
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });
    }

    public void showDialog1(View view) {
        new AlertDialog.Builder(this)
                .setTitle("提示")
                .setMessage("确定要删除吗？")
                .setPositiveButton("确定", (dialog, which) -> {
                    // 点击确定按钮执行的操作
                    Toast.makeText(this, "确定删除", Toast.LENGTH_SHORT).show();
                })
                .setNegativeButton("取消", (dialog, which) -> {
                    // 点击取消按钮执行的操作
                    Toast.makeText(this, "取消", Toast.LENGTH_SHORT).show();
                })
                .show();
    }

    public void showDialog2(View view) {
        new AlertDialog.Builder(this)
                .setTitle("请选择字体大小")
                .setSingleChoiceItems(textSizeArr, -1, (dialog, which)->{
                    index = which;
                })
                .setPositiveButton("确定", (dialog, which) -> {
                    // 点击确定按钮执行的操作
                    binding.textsizeview.setTextSize(textnumberArr[index]);
//                    textsizeview.setTextSize(textnumberArr[index]);
                })
                .setNegativeButton("取消", (dialog, which) -> {})
                .show();
    }

    public void showDialog3(View view) {
        new AlertDialog.Builder(this)
                .setTitle("请选择兴趣爱好")
                .setMultiChoiceItems(hobbyArr, null, (dialog, which, isChecked) -> {
                    // 点击选项执行的操作
                    hobby += hobbyArr[which] + " ";
                })
                .setPositiveButton("确定", (dialog, which) -> {
                    // 点击确定按钮执行的操作
                    binding.texthobbyview.setText(hobby);
//                    texthobbyview.setText(hobby);
                    hobby = "";
                })
                .setNegativeButton("取消", (dialog, which) -> {
                    hobby = "";
                })
                .show();
    }
}